package top.glike.funct.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.glike.common.annotation.Log;
import top.glike.common.core.controller.BaseController;
import top.glike.common.core.domain.AjaxResult;
import top.glike.common.core.page.TableDataInfo;
import top.glike.common.enums.BusinessType;
import top.glike.common.utils.poi.ExcelUtil;
import top.glike.funct.domain.GbArticles;
import top.glike.funct.service.IGbArticlesService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文章管理Controller
 *
 * @author Sophia
 * @date 2024-02-13
 */
@RestController
@RequestMapping("/funct/articles")
public class GbArticlesController extends BaseController {
    @Autowired
    private IGbArticlesService gbArticlesService;

    /**
     * 查询文章管理列表
     */
    // @PreAuthorize("@ss.hasPermi('funct:articles:list')")
    @GetMapping("/list")
    public TableDataInfo list(GbArticles gbArticles) {
        startPage();
        List<GbArticles> list = gbArticlesService.selectGbArticlesList(gbArticles);
        return getDataTable(list);
    }


    /**
     * 导出文章管理列表
     */
    // @PreAuthorize("@ss.hasPermi('funct:articles:export')")
    @Log(title = "文章管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GbArticles gbArticles) {
        List<GbArticles> list = gbArticlesService.selectGbArticlesList(gbArticles);
        ExcelUtil<GbArticles> util = new ExcelUtil<GbArticles>(GbArticles.class);
        util.exportExcel(response, list, "文章管理数据");
    }

    /**
     * 获取文章管理详细信息
     */
    // @PreAuthorize("@ss.hasPermi('funct:articles:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(gbArticlesService.selectGbArticlesById(id));
    }

    /**
     * 新增文章管理
     */
    // @PreAuthorize("@ss.hasPermi('funct:articles:add')")
    @Log(title = "文章管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GbArticles gbArticles) {
        return toAjax(gbArticlesService.insertGbArticles(gbArticles));
    }

    /**
     * 修改文章管理
     */
    // @PreAuthorize("@ss.hasPermi('funct:articles:edit')")
    @Log(title = "文章管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GbArticles gbArticles) {
        return toAjax(gbArticlesService.updateGbArticles(gbArticles));
    }

    /**
     * 删除文章管理
     */
    // @PreAuthorize("@ss.hasPermi('funct:articles:remove')")
    @Log(title = "文章管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(gbArticlesService.deleteGbArticlesByIds(ids));
    }
}
